#! /bin/bash

if [ $# -ne 1 ]
then
    echo "Usage: $0 archieve-file"
    exit 4
fi

if [ -e $1 ]
then
    echo -n ""
else
    echo "Archieve file do not exist"
    exit 5
fi

# extract text report data files 
echo "Extracting $1"
mkdir tmp
tar xvf $1 -C tmp
cd tmp

# matcher tcp rate data
for i in $(seq 1 6);
do
    echo "Parsing $i.txt"
    echo "value unit" > $i.dat
    grep -o "[0-9]\+.[0-9]* Mbits/sec" $i.txt >> $i.dat
done

#
tar cvf ../data-$1 [0-9].dat
cd ..
rm -r tmp

# archieve data files
#echo "Archieve data files to preprot$1.tar.gz"
#tar cvzf preport$1.tar.gz *[0-9].dat

# remove tmp text report data files
#echo "Remove txt files"
#rm *[0-9].txt
